package dao

import (
	"genealogy/models"
)

func GetAllGenealogy(Genealogy map[string]interface{}) (error, []models.Genealogy, int64) {
	var GenealogyData []models.Genealogy
	page := Genealogy["page"].(int)
	pageSize := Genealogy["limit"].(int)
	var total int64
	err := db.Table("genealogy").Select("genealogy_no, genealogy_name, update_time").Where("is_del = false").Order("genealogy_no ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&GenealogyData).Error
	return err, GenealogyData, total
}
func DelGenealogy(id string) error {
	err := db.Table("genealogy").Where("genealogy_no = ?", id).Update("is_del", true).Error
	return err
}

func UpdateGenealogy(Genealogy models.Genealogy) error {
	err := db.Table("genealogy").Where("genealogy_no = ?", Genealogy.GenealogyNo).Updates(&Genealogy).Error
	return err
}

func AddGenealogy(Genealogy models.Genealogy) error {
	err := db.Table("genealogy").Select("genealogy_no", "genealogy_name", "update_time", "is_del").Create(&Genealogy).Error
	return err
}
